package com.gdut.huayan.controller;

import com.gdut.huayan.entity.dto.PageQuery;
import com.gdut.huayan.entity.dto.Result;
import com.gdut.huayan.entity.po.Activity;
import com.gdut.huayan.entity.po.LimitName;
import com.gdut.huayan.entity.vo.ActivityVo;
import com.gdut.huayan.service.ActivityService;
import com.gdut.huayan.validation.group.GroupAdd;
import com.gdut.huayan.validation.group.GroupUpdate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

@RestController
@RequestMapping("/activity")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @PreAuthorize("hasAnyAuthority('SUPER_ADMIN')")
    @PostMapping("/getAll")
    public Result getAll(@RequestBody PageQuery pageQuery,Integer isSuiXi){
        return Result.success(activityService.getPage(pageQuery,isSuiXi));
    }

    @PreAuthorize("permitAll()")
    @GetMapping("/get")
    public Result get(Long festivalId,Long locationId){
        return Result.success(activityService.getFestivalLocationActivity(festivalId,locationId));
    }

    @PreAuthorize("hasAnyAuthority('SUPER_ADMIN')")
    @PostMapping("/add")
    public Result addActivity(@RequestBody @Validated({Default.class,GroupAdd.class}) ActivityVo activityVo){
        activityService.save(activityVo);
        return Result.success();
    }

    @PreAuthorize("hasAnyAuthority('SUPER_ADMIN')")
    @PostMapping("/update")
    public Result updateActivity(@RequestBody @Validated({Default.class,GroupUpdate.class}) Activity activity){
        activityService.updateById(activity);
        return Result.success();
    }

    @PreAuthorize("hasAnyAuthority('SUPER_ADMIN')")
    @DeleteMapping("/delete")
    public Result deleteActivity(Long activityId){
        activityService.removeById(activityId);
        return Result.success();
    }

    @PreAuthorize("hasAnyAuthority('SUPER_ADMIN')")
    @PostMapping("/limit-name/add")
    public Result addLimitName(@RequestBody @Validated({Default.class,GroupAdd.class}) List<LimitName> limitName){
        activityService.addLimitName(limitName);
        return Result.success();
    }

    @PreAuthorize("hasAnyAuthority('SUPER_ADMIN')")
    @DeleteMapping("/limit-name/delete")
    public Result deleteLimitName(Long limitNameId){
        activityService.deleteLimitName(limitNameId);
        return Result.success();
    }

    @PreAuthorize("hasAnyAuthority('SUPER_ADMIN')")
    @PostMapping("/limit-name/update")
    public Result updateLimitName(@RequestBody @Validated({Default.class,GroupUpdate.class})List<LimitName> limitName){
        activityService.updateLimitName(limitName);
        return Result.success();
    }


}
